#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <iterator>
#include <random>
#include <chrono>
using std::cin;
using std::cout;

#define F(i, l, r) for (auto i = (l); i <= (r); ++i)
#define dF(i, l, r) for (auto i = (l); i >= (r); --i)
#define F2(i, l, r) for (auto i = (l); i < (r); ++i)

void Solve();
int main() {
#ifndef PKRBT
    [[maybe_unused]] auto tmp1_ = std::freopen("arena.in", "r", stdin);
    [[maybe_unused]] auto tmp2_ = std::freopen("arena.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int tests = 1;
    // cin >> tests;
    F(t, 1, tests)
        Solve();
    return 0;
}

using LL = long long;

template<typename T>
using Vec = std::vector<T>;

std::mt19937_64 rng{(unsigned long long)std::chrono::steady_clock().now().time_since_epoch().count()};

const int MN = 1 << 17 | 7;

int n, m, K, k, q;
int a_[MN], a[MN], c_[MN];
int lg2_[MN];
int d[MN], w[MN << 1];

void Solve() {
    cin >> n >> m;
    lg2_[1] = 0;
    F(i, 2, n)
        lg2_[i] = lg2_[(i - 1) / 2 + 1] + 1;
    K = lg2_[n], k = 1 << K;
    // F(i, 1, n)
    //     std::cerr << lg2_[i] << " \n"[i == n];
    // std::cerr << "(K, k) = (" << K << ", " << k << ")\n";
    F2(i, 0, n)
        cin >> a_[i];
    F(m_, 1, m)
        cin >> c_[m_];
    dF(i, K - 1, 0) {
        static char s[MN];
        cin >> s;
        F2(j, 0, 1 << i)
            d[1 << i ^ j] = s[j] ^ '0';
    }
    F2(i, 0, n)
        w[k ^ i] = i;
    cin >> q;
    F(q_, 1, q) {
        int x[4];
        cin >> x[3] >> x[0] >> x[1] >> x[2];
        { // unroll
            int i = 0;
            for (; i + 4 <= n; i += 4) {
                a[i    ] = a_[i    ] ^ x[0];
                a[i + 1] = a_[i + 1] ^ x[1];
                a[i + 2] = a_[i + 2] ^ x[2];
                a[i + 3] = a_[i + 3] ^ x[3];
            }
            switch (n - i) {
              case 3:
                a[i + 2] = a_[i + 2] ^ x[2];
              case 2:
                a[i + 1] = a_[i + 1] ^ x[1];
              case 1:
                a[i    ] = a_[i    ] ^ x[0];
              default:
                ;
            }
        }
        // F2(i, 0, n)
        //     std::cerr << a[i] << " \n"[i + 1 == n];
        int n_ = n;
        dF(i, K - 1, 0) {
            n_ >>= 1;
            F2(j_, 0, n_) {
                int j = 1 << i ^ j_;
                w[j] = a[w[j << 1 ^ d[j]]] >= K - i
                    ? w[j << 1 ^ d[j]]
                    : w[j << 1 ^ d[j] ^ 1];
            }
        }
        LL ans = 0;
        F(m_, 1, m) {
            int c = c_[m_];
            if (c == (1 << lg2_[c])) {
                // special property A
                // std::cerr << "#" << m_ << ": " << (w[1 << (K - lg2_[c])] + 1) << '\n';
                ans ^= (LL)m_ * (w[1 << (K - lg2_[c])] + 1);
                continue;
            }
            int p = lg2_[c ^ (c & (c - 1))];
            c = (k ^ (c - 1)) >> p;
            Vec<int> cur = {w[c]};
            int lb = -1, rb = -1;
            while (c & (c - 1)) {
                int j = c & 1;
                c >>= 1;
                ++p;
                if (j) {
                    if (d[c]) {
                        if (cur.empty())
                            cur = {w[c << 1]};
                        else {
                            bool f = false;
                            Vec<int> tmp;
                            for (int cu : cur)
                                if (a[cu] >= p)
                                    tmp.push_back(cu);
                                else
                                    f = true;
                            if (lb != -1)
                                f = true;
                            cur.swap(tmp);
                            if (f)
                                cur.push_back(w[c << 1]);
                        }
                    } else {
                        if (a[w[c << 1]] >= p)
                            cur = {w[c << 1]},
                            lb = rb = -1;
                        else
                            ;
                    }
                } else {
                    if (d[c]) {
                        rb = ((c + 1) << p) - 1;
                        if (lb == -1)
                            lb = (c << 1 ^ 1) << (p - 1);
                    } else {
                        if (cur.empty())
                            rb = ((c + 1) << p) - 1;
                        else {
                            bool f = false;
                            Vec<int> tmp;
                            for (int cu : cur)
                                if (a[cu] >= p)
                                    tmp.push_back(cu);
                                else
                                    f = true;
                            if (lb != -1)
                                f = true;
                            cur.swap(tmp);
                            if (f) {
                                rb = ((c + 1) << p) - 1;
                                if (lb == -1)
                                    lb = (c << 1 ^ 1) << (p - 1);
                            }
                        }
                    }
                }
            }
            LL sum = 0;
            for (int cu : cur)
                sum += cu + 1;
            if (lb != -1)
                sum += (LL)(lb + rb + 2 - k - k) * (rb - lb + 1) / 2;
            ans ^= m_ * sum;
            // std::cerr << "#" << m_ << ": ";
            // for (int cu : cur)
            //     std::cerr << cu + 1 << " ";
            // if (lb != -1)
            //     F(i, lb, rb)
            //         std::cerr << i - k + 1 << " ";
            // std::cerr << '\n';
        }
        cout << ans << '\n';
    }
}

// GG, expected 76 pts
